if (getpeername (s, (char *) &fsocket, &i) != -1) {
port = DTranslate;
DTranslate = 0;
rq->rmtaddr = strdup (psocket (&fsocket));
if ((cp = strchr (rq->rmtaddr, ':')) != NULLCHAR)
*cp = 0;
addr = aton (rq->rmtaddr);
DTranslate = 1;
rq->rmthost = strdup (inet_ntoa (addr));
DTranslate = port;
} else {
rq->rmthost = strdup ("unknown");
rq->rmtaddr = strdup ("unknown");
}
close_s(Curproc->output);
close_s(Curproc->input);
Curproc->output = Curproc->input = s;
rq->sock = s;
/* see if we have too many connections */
if (Httpmax <= HttpUsers) {
tprintf("HTTP/1.0 503 Service Unavailable\n%s %s%s\n\n<TITLE>Busy</TITLE><H1>Busy</H1>\nTry again later.\n",HTTPHdrs[0],CTypes1[HTTPtypes[HTTPhtml].type1],HTTPtypes[HTTPhtml].type2);
HttpUsers++;
goto quit;
}
HttpUsers++;
#ifdef STATS_USE
STATS_adduse (1);
#endif
sprintf (command, "HTTP Server - Waiting (%s)", rq->rmthost);
chname (Curproc, command);
/* only allow Httpsimc connections to be active at a time */
usputs (s, "<HEAD><TITLE>400 Bad Request</TITLE></HEAD>\n<BODY><H1>400 Bad Request</H1>\nYour client sent a query that this server could not understand.<P>\nReason: Invalid HTTP/0.9 method.<P></BODY>\n");
goto quit;
}
tmp = decode (command);
cp = strchr (tmp, ' ');
if (cp == NULLCHAR) {
retval = 400;
usputs (s, "<HEAD><TITLE>400 Bad Request</TITLE></HEAD>\n<BODY><H1>400 Bad Request</H1>\nYour client sent a query that this server could not understand.<P>\nReason: No URL given.<P></BODY>\n");
goto quit;
}
*cp++ = 0;
newcommand = ++cp;
version = strchr (newcommand, ' ');
if (version != NULLCHAR)
*version++ = 0;
/* at this point, tmp=command, newcommand=ulr, and version=httpversion info */
if (!strcmp (newcommand, "/"))
newcommand++;
if (!*newcommand)
ports[rq->index].homehits++;
rq->url = strdup (newcommand);
rq->version = strdup (version);
rq->method = strdup (tmp);
length = (int) strlen (newcommand);
/* if HTTP 0.9 (no version string), only 'GET' is allowed */
if (version == NULLCHAR && strncmp (command, "GET", 3)) {
retval = 400;
httpHeaders (HTTPhtml, "400 Bad Request", rq, 0, NULLCHAR);
usputs (s, "<HEAD><TITLE>400 Bad Request</TITLE></HEAD>\n<BODY><H1>400 Bad Request</H1>\nYour client sent a query that this server could not understand.<P>\nReason: Invalid HTTP/0.9 method.<P></BODY>\n");
goto quit0;
}
/* not complete yet, but it at least logs it and responds ;-) */
poststr[0] = 0;
if (!strncmp (command, "POST", 4)){
int postsize = 0;
int headersdone = 0;
/* if posting PBBS email, open a file for the post contents */
if (!strnicmp (rq->buf, HTTPHdrs[1], strlen(HTTPHdrs[1]))) {
postsize = atoi(&rq->buf[strlen(HTTPHdrs[1])]);
continue;
} else if (!*rq->buf && !headersdone) {
headersdone = 1;
if (!postsize) {
retval = 400;
httpHeaders (HTTPhtml, "400 Bad Request", rq, 0, NULLCHAR);
usputs (s, "<HEAD><TITLE>400 Bad Request</TITLE></HEAD>\n<BODY><H1>400 Bad Request</H1>\nYour client sent an improperly formatted POST - no size given.</BODY>\n");
goto quit0;
}
/* one more line with content */
continue;
}
if (!headersdone)
continue;
if (!posted_message) {
#if 1
if (postsize <= 0)
break;
#endif
continue;
}
/* if this is a posted message, this will be our data line - save it */
strncpy (poststr, rq->buf, PLINELEN + 16);
break;
}
kalarm (0L);
if (posted_message)
goto http_bbs_entry;
/* if this is NOT an email posting, return an okay and bitbucket the posting action */
usputs (s, "<HEAD><TITLE>202 Post Accepted</TITLE></HEAD>\n<BODY><H1>202 Post Accepted</H1>\nThe TNOS server has accepted and logged your posting.</BODY>\n");
goto quit0;
}
if (!strncmp (command, "HEAD", 4))
head = 1;
if (version != NULLCHAR && !strnicmp (version, "HTTP/", 5)) {
/* we must wait to receive header lines, until a blank line */
/* not GET, HEAD, or POST, so we don't support it.... */
retval = 400;
httpHeaders (HTTPhtml, "400 Bad Request", rq, 0, NULLCHAR);
usputs (s, "<HEAD><TITLE>400 Bad Request</TITLE></HEAD>\n<BODY><H1>400 Bad Request</H1>\nYour client sent a query that this server could not understand.<P>\nReason: Invalid or unsupported method.<P></BODY>\n");
usputs (s, "<pre>\n\n\n</pre><HR><H5>For further information on TNOS can be found at <A HREF=\"http://www.lantz.com/tnos\">TNOS Central</A></H5>\n</HTML>\n");
httpHeaders (HTTPhtml, "401 Unauthorized", rq, 0, "the TNOS PBBS");
usputs (s, "<HEAD><TITLE>Authorization Failed</TITLE></HEAD>\n<BODY><H1>Authorization Failed</H1>\nThe TNOS server requires proper authorization for this URL. Either your browser does not perform authorization, or your authorization has failed.</BODY>\n");
goto quit0;
}
#ifdef STRICT_HTTPCALL
if (HTTPstrict && !(rq->privs & SYSOP_CMD) && !iscall(tmp64))
goto failauthorize0;
#endif
if (rq->privs & WAS_ANONY) {
int ii, trans;
char *cptr, *cptr2;
ii = SOCKSIZE;
trans = DTranslate; /* Save IP address translation state */
DTranslate = 0; /* Force output to be numeric IP addr*/
usputs (s, "<HEAD><TITLE>403 Post Forbidden</TITLE></HEAD>\n<BODY><H1>403 Post Forbidden</H1>\nThe TNOS server has rejected your posting.<p>\nYou do not have permission to post to this site.\n");
usputs (s, "<HEAD><TITLE>202 Post Accepted</TITLE></HEAD>\n<BODY><H1>202 Post Accepted</H1>\nThe TNOS server has accepted and logged your posting.</BODY>\n");
httpHeaders (HTTPhtml, "400 Bad Request", rq, 0, NULLCHAR);
usputs (s, "<HEAD><TITLE>400 Bad Request</TITLE></HEAD>\n<BODY><H1>400 Bad Request</H1>\nYour client sent a query that this server could not understand.<P>\nReason: No email address given.<P></BODY>\n");
}
(void) fclose (postfp);
free (toaddr);
free (subject);
goto quit0;
}
/* otherwise, it must be a regular html file in the 'bbs' directory */
}
#endif
if (is_authorized (rq) == FALSE) {
/* this url is protected and proper authentication wasn't given */
usputs (s, "<HEAD><TITLE>Authorization Failed</TITLE></HEAD>\n<BODY><H1>Authorization Failed</H1>\nThe TNOS server requires proper authorization for this URL. Either your browser does not perform authorization, or your authorization has failed.</BODY>\n");